import Vue from 'vue'
import VueRouter from 'vue-router'

import Layout from '@/views/layout'

Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push
// 修改原型对象中的push方法
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}
// 解决vue路由重复导航错误
// 获取原型对象上的push函数

export const routes = [
  {
    path: '/login',
    component: () => import('@/views/login/index')
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: '/dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: {
          label: '工作台'
        }
      },
      {
        path: '/warehouse',
        component: () => import('@/views/warehouse/index'),
        meta: {
          label: '仓库管理'
        }
      },
      {
        path: '/warehouse/details/:id',
        name: '/warehouse/details/null',
        component: () => import('@/views/warehouse/detail/index'),
        meta: {
          label: '新增仓库'
        }
      },
      {
        path: '/warehouse/details/:id',
        name: '/warehouse/details/:id',
        component: () => import('@/views/warehouse/detail/index'),
        meta: {
          label: '编辑仓库'
        }
      },
      {
        path: '/areamanage',
        component: () => import('@/views/areamanage/index'),
        meta: {
          label: '库区管理'
        }
      },
      {
        path: '/positionmanage',
        component: () => import('@/views/positionmanage/index'),
        meta: {
          label: '库位管理'
        }
      },
      {
        path: '/positionView',
        component: () => import('@/views/positionView/index'),
        meta: {
          label: '库位视图'
        }
      },
      {
        path: '/goodsManage',
        component: () => import('@/views/goodsManage/index'),
        meta: {
          label: '货品管理'
        }
      },
      {
        path: '/goodsTypeManage',
        component: () => import('@/views/goodsTypeManage/index'),
        meta: {
          label: '货品类型管理'
        }
      }
    ]
  }
]

const router = new VueRouter({
  routes
})

export default router
